<?php
/*
 * [佳喜网络!] (C)2008-2009 JiaXi Inc.
 * $Id: include.php 2008-8-13 19:28:02 pepsi.zh $
 * -------------------------------------------
 * 网址：www.he88.cn
 * -------------------------------------------
 * 这是一个共享软件，遵循我们公司的共享协议。
*/
interface CataDbInter{
	### 功能：用户登陆判断  参数：$post 记录值；#####
    function addRecord($post);
    ### 功能：获得大类 参数：$type 返回值类型
    function getRecordParent($type=true);
    ### 功能：获得小类 参数：$type 返回值类型
    function getRecordChild($type=true);
    ### 功能：通过小类得到大类  参数：$id 小类id;$field返回字段，如果没有就返回默认 ####
    function getParentByChild($id,$field='');
}
class catagory implements CataDbInter {
	public $error = array();
	public $action = '提交';
	function addRecord($post){
		global $dbtable,$dbconn;
		$flag = true;
		$var = array();
		$post = specialhtml($post,'zcontent');
		if (empty($post[zname])){
			$flag = false;
			$this->error[zname_error] = '网站名称不能为空';
		}else {
			$var[zname] = $post[zname];
		}
		$varlongth = strlen($post[zurl]);
		if($varlongth < 3){
			$flag = false;
			$this->error[zurl_error] = '网站地址有误';
		}elseif ($varlongth > 100){
			$flag = false;
			$this->error[zurl_error] = '网站地址长度不能超过100字节';
		}else {
			$var[zurl] = $post[zurl];
		}
		if (empty($post[zbelongid])){
			$flag = false;
			$this->error[zbelongid_error] = '网站类别不能为空';
		}else {
			$var[zbelongid] = $post[zbelongid];
		}
		$varlongth = strlen($post[zcontent]);
		if ($varlongth < 10) {
			$flag = false;
			$this->error[zcontent_error] = '网站内容不能小于10字节';
		}elseif ($varlongth > 2000){
			$flag = false;
			$this->error[zcontent_error] = '网站内容不能多余2000字节';
		}else {
			$var[zcontent] = $post[zcontent];
		}
		if (empty($post[userId])){
			header('location:/member/login.php');
			exit;
		}else {
			$var[zuserid] = $post[userId];
		}
		if (isset($post[zheadtitle])){
			$var[zheadtitle] = $post[zheadtitle];
		}
		if (isset($post[zheadkeyword])){
			$var[zheadkeyword] = $post[zheadkeyword];
		}
		if (isset($post[zheaddescrib])){
			$var[zheaddescrib] = $post[zheaddescrib];
		}
		if ($flag){
			$var[zdate] = time();
			$var[ztitle] = $post[ztitle];
			$var[zkeyword] = $post[zkeyword];
			if ($post[zsiteid]){
				$this->action = '修改';
				return $dbconn->updateData($var,$dbtable->site,array('zsiteid'=>$post[zsiteid]));
			}else {
				$this->action = '添加';
				return $dbconn->addData($var,$dbtable->site);
			}
		}else {
			return false;
		}
	}
	function getRecordParent($type=true){
		global $dbtable,$dbconn;
		$query = "select * from $dbtable->belong where zparentid=0 order by zbelongid asc";
		if ($type){
			return $dbconn->Fetcharray_area($query,'zbelongid','zname');
		}else {
			return $dbconn->Fetcharray($query);
		}
	}
	function getRecordChild($type=true){
		global $dbtable,$dbconn;
		$query = "select * from $dbtable->belong where zparentid!=0 order by zbelongid asc";
		if ($type){
			return $dbconn->Fetcharray_area($query,'zbelongid','zname');
		}else {
			return $dbconn->Fetcharray($query);
		}
	}
	function getParentByChild($id,$field=''){
		global $dbtable,$dbconn;
		if (empty($id)){
			return false;
		}
		$query = "select b.zname,b.zbelongid from $dbtable->belong a left join $dbtable->belong b on(a.zparentid=b.zbelongid) where a.zbelongid=$id limit 1";
		$array = $dbconn->Getonerecord($query);
		if ($field){
			return $array[$field];
		}else{
			return $array;
		}
	}
}

?>